from django.db import models
from django.conf import settings
from django.utils.translation import ugettext_lazy as _

from ..utils.choices import INFO_TYPE
from .services import get_info_attachment_path


class Info(models.Model):
    """
    信息
    """
    "内容"
    content = models.TextField(blank=False, null=False, verbose_name=_("content"))
    "类型"
    type = models.CharField(max_length=16, blank=False, null=False, choices=INFO_TYPE, verbose_name=_("info type"))
    "标题"
    title = models.CharField(max_length=128, blank=False, null=False, verbose_name=_("info title"))
    "状态"
    status = models.BooleanField(null=False, blank=True, default=False, verbose_name=_("info status"))
    "创建时间"
    created_date = models.DateTimeField(auto_now_add=True, verbose_name=_("created date"))
    "附件"
    attachment = models.FileField(upload_to=get_info_attachment_path, null=True, blank=True,
                                  verbose_name=_("attachment"))
    "用户"
    user = models.ForeignKey(settings.AUTH_USER_MODEL, blank=False, null=True, default=True, on_delete=models.CASCADE,
                             verbose_name=_("info user"))
    "项目发送方"
    send = models.ForeignKey("projects.Project", blank=False, null=True, on_delete=models.CASCADE,
                             related_name="send_project", verbose_name=_("send project"))
    "项目接受方"
    accept = models.ForeignKey("projects.Project", blank=False, null=True, on_delete=models.CASCADE,
                               related_name="accept_project", verbose_name=_("accept project"))

    class Meta:
        verbose_name = "信息"
        verbose_name_plural = "信息"
        ordering = ["created_date"]
